package com.weixin.controller;

import java.util.Calendar;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.jfinal.core.Controller;
import com.weixin.dao.Code;
import com.weixin.utils.DateUtils;

public class CodeController extends Controller{
	public Code dao = new Code();
	Calendar calendar = Calendar.getInstance();
	public Integer day = Integer.valueOf(DateUtils.getDay());
	/**
	 * 校验验证码
	 */
	public void select(){
		String code = getPara("code");
		int month = DateUtils.getCurrentMonth();
		String c = null; 
		if (month==4) {
			if (day<9) {
				c = "code1";
			}else if(day>8&&day<17){
				c = "code2";
			}else if(day>=17&&day<=24){
				c = "code3";
			}else if(day>=24){
				c = "code4";
			}
		}else {
			c = "code4";
		}
		String sql = "select * from code where " + c +"= "+code;  
		Code codes = dao.findFirst(sql);
		JSONObject json = new JSONObject();
		if (codes == null ) {
			json.put("code", "0");
		}else {
			json.put("code", "1");
		}
		renderJson(json);
	}
	
	
	/**
	 * 查询出验证码对应的省份和对应的城市和门店并且返回
	 */
	public void selectCodeInfo(){
		String code = getPara("code");
		Code codeInfo=  dao.selectCodeInfo(code);
		JSONObject json = new JSONObject();
		if (codeInfo == null ) {
			json.put("code", 0);
		}else{
			json.put("code", "1");
			json.put("info", codeInfo);
		}
		renderJson(json);
	}
}
